<?php

namespace App\Http\Controllers\Web;

use App\ConstDir\ErrorConst;
use App\Repository\Repositories\Interfaces\AttributesRepository;
use Illuminate\Http\Request;
 
class AttributeController extends BaseController
{
   
    protected $attribute_repo;
    
    public function __construct(AttributesRepository $attribute_repo)
    {
        $this->attribute_repo = $attribute_repo;
    }

    public function index(Request $request)
    {
        $type = $request->input("type","");
        
        if($type == "all"){
            //为了和分页查询保持统一 这里处理成$ret['list'];
            $attrs = $this->attribute_repo->all();
            if(isset($attrs['data'])){
                $ret['list'] = $attrs['data'];
            }else{
                $ret['list'] = [];
            }
            return $this->success(ErrorConst::SUCCESS_CODE, $ret,false);
            
        }else{
            $attr_values = $this->attribute_repo->paginate($this->perPage);
            return $this->success(ErrorConst::SUCCESS_CODE, $attr_values,true);
        }
         
    }

    public function show($id)
    {
        
    }

    public function store(Request $request)
    {
        
    }

    public function update(Request $request, $id)
    { 
        
    }

    public function delete($id)
    {
        
    }
    
}
